home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / network / exp16116.zip / HEAD.ASM < prev    next >
Assembly Source File  |  1994-04-06  |  37KB  |  1,445 lines

  1.     include    defs.asm
  2.  
  3. ;  Copyright, 1988-1993, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. code    segment word public
  19.     assume    cs:code, ds:code
  20.  
  21.     public    phd_environ
  22.     org    2ch
  23. phd_environ    dw    ?
  24.  
  25.     public    phd_dioa
  26.     org    80h
  27. phd_dioa    label    byte
  28.  
  29.     org    100h
  30. start:
  31.     jmp    start_1
  32.     extrn    start_1: near
  33.     db    "PK"
  34.     extrn    branding_msg: byte
  35.     dw    branding_msg
  36.  
  37.     even                ;put the stack on a word boundary.
  38.     dw    128 dup(?)        ;128 words of stack.
  39. our_stack    label    byte
  40.  
  41.  
  42.     extrn    int_no: byte
  43.  
  44.     public    entry_point, sys_features, flagbyte, is_186, is_286, is_386
  45. entry_point    db    ?,?,?,?        ; interrupt to communicate.
  46. sys_features    db    0        ; 2h = MC   40h = 2nd 8259
  47. is_186        db    0        ;=0 if 808[68], =1 if 80[123]86.
  48. is_286        db    0        ;=0 if 80[1]8[68], =1 if 80[234]86.
  49. is_386        db    0        ;=0 if 80[12]8[68], =1 if 80[34]86.
  50. flagbyte    db    0
  51. original_mask    db    0        ;=0 if interrupt was originally on.
  52.     even
  53.  
  54. functions    label    word
  55.     dw    f_not_implemented    ;0
  56.     dw    f_driver_info        ;1
  57.     dw    f_access_type        ;2
  58.     dw    f_release_type        ;3
  59.     dw    f_send_pkt        ;4
  60.     dw    f_terminate        ;5
  61.     dw    f_get_address        ;6
  62.     dw    f_reset_interface    ;7
  63.     dw    f_stop            ;8
  64.     dw    f_not_implemented    ;9
  65.     dw    f_get_parameters    ;10
  66.     dw    f_not_implemented    ;11
  67.     dw    f_as_send_pkt        ;12
  68.     dw    f_drop_pkt        ;13
  69.     dw    f_not_implemented    ;14
  70.     dw    f_not_implemented    ;15
  71.     dw    f_not_implemented    ;16
  72.     dw    f_not_implemented    ;17
  73.     dw    f_not_implemented    ;18
  74.     dw    f_not_implemented    ;19
  75.     dw    f_set_rcv_mode        ;20
  76.     dw    f_get_rcv_mode        ;21
  77.     dw    f_set_multicast_list    ;22
  78.     dw    f_get_multicast_list    ;23
  79.     dw    f_get_statistics    ;24
  80.     dw    f_set_address        ;25
  81.  
  82. ;external data supplied by device-dependent module:
  83.     extrn    driver_class: byte
  84.     extrn    driver_type: byte
  85.     extrn    driver_name: byte
  86.     extrn    driver_function: byte
  87.     extrn    parameter_list: byte
  88.     extrn    rcv_modes: word        ;count of modes followed by mode handles.
  89.  
  90. ;external code supplied by device-dependent module:
  91.     extrn    send_pkt: near
  92.     extrn    as_send_pkt: near
  93.     extrn    drop_pkt: near
  94.     extrn    set_address: near
  95.     extrn    terminate: near
  96.     extrn    reset_interface: near
  97.     extrn    xmit: near
  98.     extrn    recv: near
  99.     extrn    etopen: near
  100.     extrn    set_multicast_list: near
  101.     extrn    timer_isr: near
  102.  
  103. per_handle    struc
  104. in_use        db    0        ;non-zero if this handle is in use.
  105. packet_type    db    MAX_P_LEN dup(0);associated packet type.
  106. packet_type_len    dw    0        ;associated packet type length.
  107. receiver    dd    0        ;receiver handler.
  108. receiver_sig    db    8 dup(?)    ;signature at the receiver handler.
  109. class        db    ?        ;interface class
  110. per_handle    ends
  111.  
  112. handles        per_handle MAX_HANDLE dup(<>)
  113. end_handles    label    byte
  114.  
  115.     public    multicast_count, multicast_addrs, multicast_broad
  116. multicast_count    dw    0        ;count of stored multicast addresses.
  117. multicast_broad    db    0ffh,0ffh,0ffh,0ffh,0ffh,0ffh    ; entry for broadcast
  118. multicast_addrs    db    MAX_MULTICAST*EADDR_LEN dup(?)
  119.  
  120. ;the device-dependent code reads the board's address from ROM in the
  121. ;initialization code.
  122.     public    address_len, rom_address, my_address
  123. address_len    dw    EADDR_LEN        ;default to Ethernet.
  124. rom_address    db    MAX_ADDR_LEN dup(?)    ;our address in ROM.
  125. my_address    db    MAX_ADDR_LEN dup(?)    ;our current address.
  126.  
  127. rcv_mode_num    dw    3
  128.  
  129. free_handle    dw    0        ; temp, a handle not in use
  130. found_handle    dw    0        ; temp, handle for our packet
  131. receive_ptr    dd    0        ; the pkt receive service routine
  132.  
  133.     public    send_head, send_tail
  134. send_head    dd    0        ; head of transmit queue
  135. send_tail    dd    0        ; tail of transmit queue
  136.  
  137. statistics_list    label    dword
  138. packets_in    dw    ?,?
  139. packets_out    dw    ?,?
  140. bytes_in    dw    ?,?
  141. bytes_out    dw    ?,?
  142. errors_in    dw    ?,?
  143. errors_out    dw    ?,?
  144. packets_dropped    dw    ?,?        ;dropped due to no type handler.
  145.  
  146. savespss    label    dword
  147. savesp        dw    ?        ;saved during the stack swap.
  148. savess        dw    ?
  149.  
  150. their_recv_isr    dd    0        ; original owner of board int
  151. their_timer    dd    0
  152.  
  153. ;
  154. ; The following structure is used to access the registers pushed by the
  155. ; packet driver interrupt handler.  Don't change this structure without also
  156. ; changing the "bytes" structure given below.
  157. ;
  158. regs    struc                ; stack offsets of incoming regs
  159. _ES    dw    ?
  160. _DS    dw    ?
  161. _BP    dw    ?
  162. _DI    dw    ?
  163. _SI    dw    ?
  164. _DX    dw    ?
  165. _CX    dw    ?
  166. _BX    dw    ?
  167. _AX    dw    ?
  168. _IP    dw    ?
  169. _CS    dw    ?
  170. _F    dw    ?            ; flags, Carry flag is bit 0
  171. regs    ends
  172.  
  173. ;
  174. ; bits in the _F register.
  175. ;
  176. CY    equ    0001h
  177. EI    equ    0200h
  178.  
  179.  
  180. ;
  181. ; This structure is a bytewise version of the "regs" structure above.
  182. ;
  183. bytes    struc                ; stack offsets of incoming regs
  184.     dw    ?            ; es, ds, bp, di, si are 16 bits
  185.     dw    ?
  186.     dw    ?
  187.     dw    ?
  188.     dw    ?
  189. _DL    db    ?
  190. _DH    db    ?
  191. _CL    db    ?
  192. _CH    db    ?
  193. _BL    db    ?
  194. _BH    db    ?
  195. _AL    db    ?
  196. _AH    db    ?
  197. bytes    ends
  198.  
  199.     public    their_isr
  200. their_isr    dd    0        ; original owner of pkt driver int
  201.  
  202.     public    our_isr
  203. our_isr:
  204.     jmp    short our_isr_0        ;the required signature.
  205.     nop
  206.     db    'PKT DRVR',0
  207.  
  208.  
  209. our_isr_open:
  210.     push    ax            ; save lots of registers
  211.     push    bx
  212.     push    cx
  213.     push    dx
  214.     push    si
  215.     push    di
  216.     push    bp
  217.     push    ds
  218.     push    es
  219.  
  220.     call    etopen            ; init the card
  221.     jc    our_isr_no_init
  222.  
  223.     mov    si,offset rom_address    ;copy their original address to
  224.     movseg    es,ds
  225.     mov    di,offset my_address    ;  their current address.
  226.     mov    cx,MAX_ADDR_LEN/2
  227.     rep    movsw
  228.  
  229.     cmp    rcv_modes+2[3*2],0    ;does mode 3 exist?
  230.     stc                ;make sure we generate an error!
  231.     je    our_isr_no_init        ;no.
  232.     call    rcv_modes+2[3*2]    ;  call it.
  233.     clc
  234.  
  235. our_isr_no_init:
  236.     pop    es            ; restore lots of registers
  237.     pop    ds
  238.     pop    bp
  239.     pop    di
  240.     pop    si
  241.     pop    dx
  242.     pop    cx
  243.     pop    bx
  244.     pop    ax
  245.     mov    dh,CANT_RESET        ; (actually can't initialize)
  246.     jc    our_isr_error
  247.     or    flagbyte,CALLED_ETOPEN    ; remember this fact
  248.     jmp    short our_isr_cont
  249.  
  250.  
  251. our_isr_0:
  252.     assume    ds:nothing
  253.     push    ax
  254.     push    bx
  255.     push    cx
  256.     push    dx
  257.     push    si
  258.     push    di
  259.     push    bp
  260.     push    ds
  261.     push    es
  262.     cld
  263.     mov    bx,cs            ;set up ds.
  264.     mov    ds,bx
  265.     assume    ds:code
  266.     mov    bp,sp            ;we use bp to access the original regs.
  267.     and    _F[bp],not CY        ;start by clearing the carry flag.
  268.  
  269.   if 0
  270.     test    _F[bp],EI        ;were interrupt on?
  271.     jz    our_isr_ei        ;no, don't turn them back on.
  272.     sti                ;yes, turn them back on.
  273. our_isr_ei:
  274.   endif
  275.  
  276.     test    flagbyte,CALLED_ETOPEN    ; have we initialized the card?
  277.     jz    our_isr_open        ; no
  278. our_isr_cont:
  279.     mov    bl,ah            ;jump to the correct function.
  280.     xor    bh,bh
  281.     cmp    bx,25            ;only twenty five functions right now.
  282.     ja    f_bad_command
  283.     add    bx,bx            ;*2
  284. ;
  285. ; The functions are called with all the original registers except
  286. ; BX, DH, and BP.  They do not need to preserve any of them.  If the
  287. ; function returns with cy clear, all is well.  Otherwise dh=error number.
  288. ;
  289.     call    functions[bx]
  290.     assume    ds:nothing
  291.     jc    our_isr_error
  292. our_isr_return:
  293.     pop    es
  294.     pop    ds
  295.     pop    bp
  296.     pop    di
  297.     pop    si
  298.     pop    dx
  299.     pop    cx
  300.     pop    bx
  301.     pop    ax
  302.     iret
  303.  
  304. our_isr_error:
  305.     assume    ds:nothing
  306.     mov    bp,sp            ;we use bp to access the original regs.
  307.     mov    _DH[bp],dh
  308.     or    _F[bp],CY        ;return their carry flag.
  309.     jmp    short our_isr_return
  310.  
  311. f_bad_command:
  312.     assume    ds:code
  313.     extrn    bad_command_intercept: near
  314.     mov    bx,_BX[bp]
  315.     call    bad_command_intercept
  316.     mov    _BX[bp],bx
  317.     mov    _DX[bp],dx
  318.     jnc    our_isr_return
  319.     jmp    our_isr_error
  320.  
  321.     public    re_enable_interrupts
  322. re_enable_interrupts:
  323. ; Possibly re-enable interrupts.  We put this here so that other routines
  324. ; don't need to know how we put things on the stack.
  325.     test    _F[bp], EI        ; Were interrupts enabled on pkt driver entry?
  326.     je    re_enable_interrupts_1    ; No.
  327.     sti                ; Yes, re-enable interrupts now.
  328. re_enable_interrupts_1:
  329.     ret
  330.  
  331.  
  332. f_not_implemented:
  333.     mov    dh,BAD_COMMAND
  334.     stc
  335.     ret
  336.  
  337.  
  338. f_driver_info:
  339. ;    As of 1.08, the handle is optional, so we no longer verify it.
  340. ;    call    verify_handle
  341.     cmp    _AL[bp],0ffh        ; correct calling convention?
  342.     jne    f_driver_info_1        ; ne = incorrect, fail
  343.  
  344.                     ;Fo